import requests
from concurrent.futures import ThreadPoolExecutor

# 定义目标 URL
BASE_URL = "http://localhost:3001/api/v1/etcm/mineRule/人参"

# 定义发送请求的函数
def send_request():
    try:
        # 发送 GET 请求
        response = requests.get(BASE_URL)
        # 打印响应状态码和内容
        print(f"Response Status Code: {response.status_code}")
        print(f"Response Content: {response.text[:100]}...")  # 打印前 100 个字符
        return response.status_code
    except requests.exceptions.RequestException as e:
        # 捕获异常并打印错误信息
        print(f"Error occurred: {e}")
        return None

# 主函数
def main():
    # 使用 ThreadPoolExecutor 实现并发
    with ThreadPoolExecutor(max_workers=3) as executor:
        # 提交三个任务
        futures = [executor.submit(send_request) for _ in range(3)]
        
        # 等待所有任务完成并收集结果
        results = [future.result() for future in futures]
    
    # 打印所有请求的结果
    print("All requests completed. Results:")
    print(results)

if __name__ == "__main__":
    main()